<template>

  <div style="height: 100vh;background-image:url('src/img/WechatIMG75.jpg');background-size: cover;overflow: hidden">
    <el-container>
      <!--  头部信息：log -->
      <el-header style="padding: 30px">
        <!--        栅格之间间隔50-->
        <el-row :gutter="50">
          <el-col :span="19">
            <span style="font-size: 30px;font-weight: bolder;color:#fff">网上图书购物系统</span>
          </el-col>
        </el-row>
      </el-header>


      <el-main>

        <el-row :gutter="40">
          <el-col :span="14">
            <el-image src=""></el-image>
          </el-col>
          <el-col :span="8">
            <el-card style="margin-top: 80px">
              <h3 style="text-align: center">用户注册</h3>
              <el-form label-position="top">
                <el-form-item label="用户名">
                  <el-input placeholder="请输入用户名" v-model="user.username"></el-input>
                </el-form-item>
                <el-form-item label="密码">
                  <el-input type="password" placeholder="请输入密码" v-model="user.password"></el-input>
                </el-form-item>
                <el-form-item label="昵称">
                  <el-input placeholder="请输入昵称" v-model="user.nickname"></el-input>
                </el-form-item>
                <el-form-item label="手机号">
                  <el-input placeholder="请输入手机号" v-model="user.phone"></el-input>
                </el-form-item>
                <el-form-item>
                  <div  class="div" style="width: 100%; display: flex; justify-content: center;">
                    <el-button type="primary" style="width: 200px" @click="userReg()">注册</el-button>
                    <el-button type="primary" style="width: 200px" @click="router.push('/login')">登录</el-button>
                  </div>
                </el-form-item>
              </el-form>
            </el-card>

          </el-col>
        </el-row>
      </el-main>
    </el-container>
  </div>
</template>


<script setup>

import {ref} from "vue";
import axios from "axios";
import {ElMessage} from "element-plus";
import router from "@/router";
const user = ref({
  username: '',
  password: '',
  nickname: '',
  phone: ''
})

const userReg= () =>{
  let data = JSON.stringify(user.value);
  axios.post("/api/UserRegServlet",data)
      .then((request) =>{
        if (request.data.code === 1){
          ElMessage.success("注册成功");
          user.value.username = '';
          user.value.password = '';
          user.value.nickname = '';
          user.value.phone = '';
          router.push("/login");
        }else {
          ElMessage.error("注册失败");
        }
      })

}

</script>

<style scoped>

</style>